//
//  DHCityListViewController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/1/3.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHCityListViewController.h"
#import "DHCityListCell.h"

@interface DHCityListViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *localCityArray;

@end

@implementation DHCityListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navView.hidden = YES;
    
    self.localCityArray = @[@"北京",@"上海",@"广州",@"深圳",@"杭州",@"成都",@"重庆",@"昆明",@"长沙",@"武汉",@"沈阳",@"福州"];
    
    self.view.backgroundColor = [UIColor colorWithHexString:@"#4a4a4a"];
    
    [self.tableView registerClass:[DHCityListCell class] forCellReuseIdentifier:@"kDHCityListCell"];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}

- (IBAction)backAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.localCityArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 57;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHCityListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"kDHCityListCell" forIndexPath:indexPath];
    cell.titleLabel.text = [self.localCityArray objectAtIndex:indexPath.row];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.selectImgView.hidden = YES;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    DHCityListCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//    cell.selectImgView.hidden = NO;
//    NSString *cityString = [self.localCityArray objectAtIndex:indexPath.row];
//    [[NSUserDefaults standardUserDefaults] setObject:cityString forKey:USER_SELECT_CITY];
//    [[NSUserDefaults standardUserDefaults] synchronize];
    [self dismissViewControllerAnimated:YES completion:nil];
    postNWithObj(@"city_list_selected", @{@"city":[self.localCityArray objectAtIndex:indexPath.row]});
}

@end
